#ifndef __mytime__
#define __mytime__

void setrtctime()  // 从互联网同步时间到芯片
{
  timeClient.update();
  // The formattedDate comes with the following format: 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedDate();
  // Serial.println(formattedDate);
  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  // Serial.print("DATE: ");
  // Serial.println(dayStamp);
  rtc.set(timeClient.getSeconds(),
          timeClient.getMinutes(),
          timeClient.getHours(),
          timeClient.getDay(),
          dayStamp.substring(8, 10).toInt(),
          dayStamp.substring(5, 7).toInt(),
          dayStamp.substring(2, 4).toInt());
  //  RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
}

void printtime() {
  // 显示互联网时间
  timeClient.update();
  formattedDate = timeClient.getFormattedDate();
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  Serial.print("NTP DateTime: ");
  Serial.print(timeClient.getFormattedTime());
  Serial.print(" ");
  Serial.print(dayStamp.substring(0, 4));
  Serial.print("/");
  Serial.print(dayStamp.substring(5, 7));
  Serial.print("/");
  Serial.print(dayStamp.substring(8, 10));
  Serial.print(" - DOW: ");
  Serial.println(timeClient.getDay());
}

#endif